<?php
namespace app\admin\loglic;

class Category
{
    public function fields($data)
    {
        $fields = [
            'html_1' => [
                'order'           => 1,
                'type'            => 'html',
                'value'           => '<div class="row"><div class="col-12 col-md-8">',
            ],
            'term_id' => [
                'order'           => 11,
                'type'            => 'hidden',
                'value'           => $data['term_id'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '80',
                'data-width-unit' => 'px',
                'data-sortable'   => true,
                'data-sort-name'  => 'term_id',
                'data-order'      => 'asc',
            ],
            'term_parent' => [
                'order'           => 73,
                'type'            => 'select',
                'value'           => $data['term_parent'],
                'option'          => DcTermOption(['module'=>input('get.term_module')]),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => 100,
            ],
            'term_type' => [
                'order'           => 21,
                'type'            => 'hidden',
                'value'           => 'category',
                'order'           => 21,
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'term_name' => [
                'order'           => 31,
                'type'            => 'text',
                'value'           => $data['term_name'],
                'required'        => true,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
            ],
            'term_slug' => [
                'order'           => 41,
                'type'            => 'text',
                'value'           => $data['term_slug'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
            ],
            'term_title' => [
                'order'           => 42,
                'type'            => 'text',
                'value'           => $data['term_title'],
            ],
            'term_keywords' => [
                'order'           => 43,
                'type'            => 'text',
                'value'           => $data['term_keywords'],
            ],
            'term_description' => [
                'order'           => 44,
                'type'            => 'text',
                'value'           => $data['term_description'],
            ],
            'html_2'      => [
                'order'           => 201,
                'type'            => 'html',
                'value'           => '</div><div class="col-12 col-md-4">',
            ],
            'term_status' => [
                'order'           => 61,
                'type'            => 'select',
                'value'           => DcEmpty($data['term_status'],'normal'),
                'option'          => ['normal'=>lang('normal'),'hidden'=>lang('hidden')],
                'data-filter'     => true,
                'data-visible'    => false,
            ],
            'term_status_text' => [
                'order'           => 71,
                'data-title'      => lang('term_status'),
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'term_order' => [
                'order'           => 211,
                'type'            => 'number',
                'value'           => intval($data['term_order']),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-sortable'   => true,
            ],
            'term_count' => [
                'order'           => 221,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => '100',
            ],
            'term_action' => [
                'order'           => 231,
                'type'            => 'text',
                'value'           => DcEmpty($data['term_action'],'index'),
            ],
            'term_controll' => [
                'order'           => 241,
                'type'            => 'text',
                'value'           => DcEmpty($data['term_controll'],'category'),
            ],
            'term_module' => [
                'order'           => 251,
                'type'            => 'text',
                'value'           => DcEmpty($data['term_module'],'common'),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => 100,
                'data-formatter'  => 'daicuo.admin.table.formatter',
            ],
            'term_info' => [
                'order'           => 261,
                'type'            => 'textarea',
                'value'           => $data['term_info'],
                'rows'            => 4,
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'html_3' => [
                'order'           => 999,
                'type'              => 'html',
                'value'             => '</div></div>',
            ]
        ];
        //表单扩展字段自动处理
        $extend = [];
        foreach(config('custom_fields.term_meta')  as $key=>$value){
            if( in_array($value['attr-type'],['common','category']) ){
                $extend[$key] = $value;
            }
        }
        if($extend){
            $fields = DcArrayPush($fields, DcFields($extend, $data), 'html_2');
        }
        //返回所有表单字段
        return $fields;
    }

}